<?php
namespace app\index\controller;


use think\Db;
use think\View;
use User;


class Index extends Base
{


    public function indexHtml()
    {

        $view = new View();
        $view->name = 'index';
        return $view->fetch('index');

    }

public function regHtml(){
	
	
	$view=new View();
	return $view->fetch('reg');
	
}
    public function loginHtml()
    {

        $view = new View();
        $view->name = 'index';
        return $view->fetch('login');

    }



    public function index()
    {
        $result = Db::table(TableName::$USER)
            ->where('id', $this->getParam()->id)
            ->find();

        return $this->response($result);
    }

    public function addUser()
    {


        $result = Db::table(TableName::$USER)->insert(array("name" => '1111'));

        return $this->response($result);
    }

    /**
     * @return string
     * 用户登录
     */
    public function login()
    {


        if ($_POST) {

            if ($this->getParam()['nickname'] == null) {
                return $this->responseFail('用户名不能为空');
            } else if ($this->getParam()['pwd'] == null) {
                return $this->responseFail('密码不能为空');
            } else {

                $u = Db::table(TableName::$USER)->where('nickname', $this->getParam()['nickname'])->find();


                if ($u == null) {

                    return $this->responseFail('用户不存在');
                } else {
                    if ($u['pwd'] == md5($this->getParam()['pwd'])) {
                        return $this->response($u);
                    } else {
                        return $this->responseFail('密码错误');
                    }
                }


                return $this->response($u);

            }

        } else {
            return $this->responseFail('不支持其他类型传值');
        }
    }
}
